<?php
require_once(dirname(__FILE__) . '/inc/config.inc.php');
IsModelPriv('goodsorder');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>renl</title>
    <link href="templates/style/admin.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="templates/js/jquery.min.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->

    <link href="layui/css/layui.css" rel="stylesheet" type="text/css" media="all"/>
    <script src="layui/layui.all.js"></script>
</head>
<body>
<style>
    .layui-table-cell { /*最后的pic为字段的field*/
        height: 100%;
        max-width: 100%;
        height: auto;
        white-space: normal;
        word-wrap: break-word;
        word-break: break-all;
    }
    .layui-layout-body {
        overflow: auto;
    }
</style>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <!-- 右表 -->
        <div class="layui-col-sm12">
            <div class="layui-card">

                <div class="layui-card-header">提示：</div>
                <div class="layui-col-sm12 layui-col-space15">
                    <div class="layui-col-sm5 ">
                        <div class="layui-card-header">奖励分类</div>
                        <div class="layui-card-header layuiadmin-card-header-auto">
                            <button class="layui-btn layuiadmin-btn-tags" data-type="add">添加奖励类型</button>
                        </div>
                        <table id="tasktypelist" lay-filter="tasktypelist_f"></table>
                        <script type="text/html" id="table-pic">
                            {{#  if(d.picurl_url !=""){ }}
                            <img src="{{d.picurl_url}}" width="90" height="90">
                            {{#  } }}
                        </script>
                        <script type="text/html" id="table_status1">
                            {{#  if(d.checkinfo =="1"){ }}
                            <a class="layui-btn  layui-btn-xs">已审</a>
                            {{#  } }}
                            {{#  if(d.checkinfo =="0"){ }}
                            <a class="layui-btn layui-btn-danger layui-btn-xs">未审</a>
                            {{#  } }}
                        </script>
                        <script type="text/html" id="table-list-op1">
                            <a class="layui-btn layui-btn-success layui-btn-xs" lay-event="edit">
                                <i class="layui-icon layui-icon-edit"></i>修改
                            </a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
                                <i class="layui-icon layui-icon-delete"></i>删除
                            </a>
                        </script>
                    </div>
                    <div class="layui-col-sm7 ">
                        <div class="layui-card-header">奖励列表</div>
                        <div class="layui-card-header layuiadmin-card-header-auto">
                            <button class="layui-btn layui-btn-danger layuiadmin-btn-tags" data-type="add_detail">添加奖励</button><button class="layui-btn layuiadmin-btn-tags" data-type="excel">导出奖励分类到Excel</button>
                        </div>
                        <table id="tasklist" lay-filter="tasklist_f"></table>
                        <script type="text/html" id="table-pic2">
                            {{#  if(d.picurl_url !=""){ }}
                            <img src="{{d.pciurl_url}}" width="90" height="90">
                            {{#  } }}
                        </script>
                        <script type="text/html" id="table-list-op2">
                            <a class="layui-btn layui-btn-success layui-btn-xs" lay-event="edit">
                                <i class="layui-icon layui-icon-edit"></i>修改
                            </a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
                                <i class="layui-icon layui-icon-delete"></i>删除
                            </a>
                        </script>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<script>

    layui.config({
        base: 'layui/lay/modules/'
    }).extend({
        admin: 'admin',
        view: 'view'
    }).use(['table', 'admin','view'], function () {

        //无需再执行layui.use()方法加载模块，直接使用即可
        var form = layui.form,
            layer = layui.layer,
            admin = layui.admin,
            view = layui.view,
            table = layui.table;
        //第一个实例
        table.render({
            elem: '#tasktypelist'
            , url: 'json/task/type.php' //数据接口
            , page: true //开启分页
            , cellMinWidth: 100
            , cols:
                [[ //表头
                    {field: 'id', title: 'ID',width:60}
                    , {field: 'classname', title: '分类名称'}
                    , {title: '分类图片',  align: 'center', toolbar: '#table-pic'}
                    , {field: 'orderid',align: 'center', title: '排序',width:60}
                    , {field: 'status', title: '状态',toolbar: '#table_status1'}
                    , {field: 'op', title: '操作',toolbar:'#table-list-op1',width:160}
                ]],
            limit: 5,
            limits: [10, 15, 20, 25, 30],
            text: {none: '暂无数据'}
        });
        //第2个实例
        table.render({
            elem: '#tasklist'
            , url: 'json/task/list.php' //数据接口
            , page: true //开启分页
            , cellMinWidth: 100
            , cols:
                [[ //表头
                    {field: 'id', title: 'ID',width:80}
                    , {field: 'classname', title: '分类名称'}
                    , {field: 'title', title: '任务名称'}
                    // , {title: '任务图片',  align: 'center', toolbar: '#table-pic'}
                    , {field: 'value', title: '虚拟值', align: 'center'}
                    , {field: 'orderid',align: 'center', title: '排序'}
                    , {field: 'status', title: '状态'}
                    , {field: 'op', title: '操作',toolbar:'#table-list-op1',width:160}
                ]],
            limit: 10,
            limits: [10, 15, 20, 25, 30],
            text: {none: '暂无数据'}
        });

        var active = {
            add: function () {
                layer.open({
                    type: 2,
                    skin: 'layui-layer-molv', //样式类名
                    title: '添加奖励类型',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['460px', '480px'],
                    content: 'task_add.php',
                    end:function () {
                        table.reload('tasktypelist'); //重载表格
                    }
                });


            },
            add_detail: function () {
                layer.open({
                    type: 2,
                    skin: 'layui-layer-molv', //样式类名
                    title: '添加奖励',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['460px', '680px'],
                    content: 'task_detail_add.php',
                    end:function () {
                        table.reload('tasklist'); //重载表格
                    }
                });


            },
            excel: function () {
                console.log("导出中");
                window.open('json/task/task2Excel.php');


            }
        };
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听工具条
        table.on('tool(tasktypelist_f)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除该记录？', function (index) {
                    $.ajax({
                        url: "json/task/task_type_do.php",
                        data: {
                            "field": [],
                            "id": data.id,
                            'action': 'del'
                        },
                        type: "POST",
                        success: function () {
                            layer.close(index); //关闭弹层

                            //登入成功的提示与跳转
                            layer.msg('删除成功', {offset: '15px', icon: 1, time: 1000}, function () {
                                table.reload('tasktypelist'); //数据刷新
                            });


                        }
                    });
                });
            } else if (obj.event === 'edit') {
                console.log(data);
                layer.open({
                    type: 2,
                    skin: 'layui-layer-molv', //样式类名
                    title: '修改奖励类型',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['460px', '480px'],
                    content: 'task_edit.php?id='+data.id,
                    end:function () {
                        table.reload('tasktypelist'); //重载表格
                    }
                });
            } else if (obj.event === 'caipin') {
                console.log("数据详情");

                console.log(data);
                admin.popup({
                    title: data.shopname + '商家菜品管理'
                    , area: ['800px', '680px']
                    , id: 'LAY-popup-content-tags'
                    , success: function (layero, index) {
                        view(this.id).render('shop/shop_goods_list', data).done(function () {
                        });

                    }

                });
            }
        });

        //监听工具条
        table.on('tool(tasklist_f)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除该记录？', function (index) {
                    $.ajax({
                        url: "json/task/task_detail_do.php",
                        data: {
                            "field": [],
                            "id": data.id,
                            'action': 'del'
                        },
                        type: "POST",
                        success: function () {
                            layer.close(index); //关闭弹层

                            //登入成功的提示与跳转
                            layer.msg('删除成功', {offset: '15px', icon: 1, time: 1000}, function () {
                                table.reload('tasklist'); //数据刷新
                            });


                        }
                    });
                });
            } else if (obj.event === 'edit') {
                console.log(data);
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan', //样式类名
                    title: '修改奖励',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['460px', '680px'],
                    content: 'task_detail_edit.php?id='+data.id,
                    end:function () {
                        table.reload('tasklist'); //重载表格
                    }
                });
            }
        });
    });
</script>
</body>
</html>